function [a,T,v,pEE]=getBoundedWiener(x,y,numLags,sig2)
if nargin<4
    sig2=0;
end
%%

sigx=full(std(x));
sigy=full(std(y));
% [Rw]=autocorr(y,2*numLags);
% [Rws]=crosscorr(y,x,numLags);
[Rws,Rw]=multicross2var(y,x,numLags);
t=2*numLags+1;
% T=zeros(t);
v=Rws(:)*sigy;
T=bsxfun(@minus,1:t,(1:t)');
T=Rw(abs(T)+1)*sigy^2;
a=(T+eye(t)*sig2)\v;%plot(a);title(sprintf('sig2=%f',sig2));
if nargout>3
    %%
    tmp=conv(full(y)-mean(y),a,'full');tmp=tmp(numLags+1:numel(tmp)-numLags);
    sqera=norm(x(:)-tmp).^2;sqerbl=norm(x).^2;
    pEE=(sqerbl-sqera)./(sqerbl);
end